package come.example.domain.strategy.model.entity;

import come.example.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/*
策略实体
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public class StrategyEntity {
    /*抽奖策略ID*/
    private Long strategyId;
    /*抽奖策略描述*/
    private String strategyDesc;
    /*抽奖规则模型 rule_weight, rule_blacklist*/
    private String ruleModels;

    public String[] ruleModels(){
        if(StringUtils.isBlank(ruleModels)) return new String[0];
        //split 方法会返回一个字符串数组，其中包含原字符串中以 , 为分隔符的各个部分
        return ruleModels.split(Constants.SPLIT);
    }

    public String getRuleWeight(){
        String[] ruleModels = this.ruleModels();
        for(String ruleModel : ruleModels){
            if("rule_weight".equals(ruleModel)) {
                return ruleModel;//如果是权重，就返回权重
            }
            //log.info(ruleModel);
        }
        return null;
    }
}
